﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyThuVien.Business;
using System.Windows.Forms;

namespace QuanLyThuVien.DataAccess
{
    class SahDAL
    {
        clsDatabase db = new clsDatabase();
        public void ThemMaSach(Sach DSBus)
        {
            db.ThuThiSQL("insert into tbSach values ('" + DSBus.MaSach + "','" + DSBus.MaDauSach + "')");
        }

        public void LayDLlenDG(DataGridView dg)
        {
            db.LoadLenDG(dg, "select S.TenSach,DS.MaDauSach,DS.MaSach from tbSach DS, tbDauSach S where DS.MaDauSach=S.MaDauSach");
        }

        public string LoadMaDS(string maDS, string tenSach)
        {
            maDS = db.LoadLenLable("select MaDauSach from tbDauSach where TenSach=N'" + tenSach + "'");
            return maDS;
        }

        public string LoadMaSach(string tenSach, string maSach)
        {
            maSach = db.LoadLenLable("select MaDauSach from tbDauSach where TenSach=N'" + tenSach + "'");
            return maSach;
        }

        public bool KiemTraDL(string maDS)
        {
            return db.KiemTra("select count (*) from tbSach where MaDauSach='" + maDS + "'");
        }

        public void XoaMaSach(string maSach)
        {
            db.ThuThiSQL("delete from tbSach where MaSach=N'" + maSach + "'");
        }

        public int LaySachCoMa(string maDS)
        {
             string SL= db.LoadLenLable("select count (*) from tbSach where MaDauSach=N'" + maDS + "'");
             return int.Parse(SL);
        }

        public void LayMaSachLenCB(ComboBox cb, string MaDS)
        {
            db.LoadLenCombobox(cb, "select MaSach from tbSach where MaDauSach=N'" + MaDS + "'and MaSach not in (select MaSach from tbPhieuMuon where NgayTra =N'"+"  /  /"+"')", 0);
        }

        public void XoaTheoDauSach(string DauSach)
        {
            db.ThuThiSQL("delete from tbSach where MaDauSach=N'" + DauSach + "'");
        }
    }
}
